package com.lsq.tucao.express.controller;

import com.lsq.tucao.express.response.JsonResult;
import com.lsq.tucao.express.service.ManageMyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/manage-my")
public class ManageMyController {

    @Autowired
    private ManageMyService manageMyService;

    /**
     * @author lsq
     * @description 管理我的吐槽
     * @param current 页码
     * @param size 每页条数
     * @param username 用户名
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/23 20:37
     */
    @GetMapping("/tucao")
    public JsonResult getMyTucao(@RequestParam(required = false,defaultValue = "1") Integer current,
                                 @RequestParam(required = false,defaultValue = "10") Integer size,
                                 @RequestParam String username){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("username:{}",username);

        return manageMyService.getMyTucao(current, size, username);
    }

    /**
     * @author lsq
     * @description 管理我的鸡汤
     * @param current 页码
     * @param size 每页条数
     * @param username 用户名
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/23 20:37
     */
    @GetMapping("/heart")
    public JsonResult getMyHeart(@RequestParam(required = false,defaultValue = "1") Integer current,
                                 @RequestParam(required = false,defaultValue = "10") Integer size,
                                 @RequestParam String username){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("username:{}",username);

        return manageMyService.getMyHeart(current,size,username);
    }

    /**
     * @author lsq
     * @description 管理我的赞
     * @param current 页码
     * @param size 每页条数
     * @param userId 用户id
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/23 20:37
     */
    @GetMapping("/like")
    public JsonResult getMyLike(@RequestParam(required = false,defaultValue = "1") Integer current,
                                 @RequestParam(required = false,defaultValue = "10") Integer size,
                                 @RequestParam Long userId){
        log.debug("current:{}",current);
        log.debug("size:{}",size);
        log.debug("userId:{}",userId);

        return manageMyService.getMyLike(current, size, userId);
    }

    /**
     * @author lsq
     * @description 删除鸡汤或吐槽
     * @param id 鸡汤id或吐槽id
     * @param flag true->删除吐槽 false->删除鸡汤
     * @return com.lsq.tucao.express.response.JsonResult
     * @create 2021/4/25 18:23
     */
    @PutMapping("/delete")
    public JsonResult deleteTucaoOrHeart(@RequestParam Long id,
                                         @RequestParam Boolean flag){
        if(flag){
            return manageMyService.delMyTucao(id);
        }else {
            return manageMyService.delMyHeart(id);
        }
    }
}
